// nbmade-modules/nbmade-iot/src/main/java/com/nbcio/iot/controller/IotNodeTemplateController.java
package com.nbcio.iot.controller;

import com.nbcio.common.core.domain.R;

import lombok.RequiredArgsConstructor;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/iot/nodered")
@RequiredArgsConstructor
public class IotNodeTemplateController {

    @GetMapping("/templates")
    public R<List<Map<String, Object>>> getNodeTemplates() {
        List<Map<String, Object>> templates = List.of(
            Map.of(
                "type", "device-event",
                "name", "设备事件",
                "category", "input",
                "icon", "connection",
                "description", "监听设备上下线事件",
                "config", Map.of(
                    "eventType", "online",
                    "deviceCode", ""
                )
            ),
            Map.of(
                "type", "mqtt-out",
                "name", "MQTT输出",
                "category", "output",
                "icon", "promotion",
                "description", "发送消息到MQTT主题",
                "config", Map.of(
                    "topic", "",
                    "qos", 0
                )
            ),
            Map.of(
                "type", "alarm",
                "name", "告警",
                "category", "output",
                "icon", "warning",
                "description", "触发告警通知",
                "config", Map.of(
                    "alarmType", "threshold",
                    "threshold", 100,
                    "operator", ">"
                )
            )
        );
        return R.ok(templates);
    }
}
